﻿$(function () {


    $(".panel-filter-toogle").click(function () {
        $(".panel-filter-toogle i").toggle();
        $(".panel-filter-body").toggle();

    });

    $("#chkgridAll").change(function () {
        $(".chkgrid").prop("checked", $(this).prop("checked"));
    });



    $(".panel-datatable .pagination a").click(function () {
        var currentPage = $(this).html();
        $("#Paging_CurrentPage").val(currentPage);
        $("#IdsForSort").val("");
        $("#IdsForApprove").val("");
        $("#IdsForDelete").val("");
        $(".form-filter").submit();
    });


    $("#ButtonSortSave").click(function () {
        var currentPage = $(".panel-datatable .pagination .active a").html();
        $("#Paging_CurrentPage").val(currentPage);
        var idList = "";
        $(".panel-datatable .datakeyfield").each(function () {
            idList += $(this).html() + ",";
        });
        $("#IdsForSort").val(idList);
        $("#IdsForApprove").val("");
        $("#IdsForDelete").val("");
        $(".form-filter").submit();
    });



    $("#ButtonApproveSave").confirmModal({
        confirmDirection: "ltr",
        confirmCallback: function () {

            var idList = "";

            $("#datagrid .chkgrid:checked").each(function () {
                var id = $(this).attr("id").replace("chkgrid-", "");
                idList += id + ",";
            });

            $("#IdsForApprove").val(idList);
            $("#IdsForSort").val("");
            $("#IdsForDelete").val("");
            $(".form-filter").submit();
        }
    });




    $("#ButtonDeleteSelected").confirmModal({
        confirmDirection: "ltr",
        confirmCallback: function () {

            var idList = "";

            $("#datagrid .chkgrid:checked").each(function () {
                var id = $(this).attr("id").replace("chkgrid-", "");
                idList += id + ",";
            });

            $("#IdsForDelete").val(idList);
            $("#IdsForApprove").val("");
            $("#IdsForSort").val("");
            $(".form-filter").submit();
        }
    });

    $(".DeleteButton").each(function () {
        var deleteLink = $(this).attr("data-confirm-href");
        $(this).confirmModal({
            confirmDirection: "ltr",
            confirmCallback: function () {
                parent.location = deleteLink;
            }
        });
    });

    $("#datagrid").dataTable({
        "oLanguage": {
            "sEmptyTable": $("#sEmptyTable").val()
        },
        
        "bPaginate": false,
        "bFilter": false,
        "bInfo": false
        
    });
    $(".datepicker").datepicker();

    $("#datagrid tbody").sortable();

    $("#datagrid tr td:first-child").each(function () {
        $(this).addClass("datagrid-first-td");
    });

    $("#datagrid th:first-child").each(function () {
        $(this).addClass("datagrid-first-td");
    });
    

    $(".multiple").multiselect(
        {
        includeSelectAllOption: true,
        allSelectedText: "",
        selectAllText: $(".multiple").attr("selectalltext"),
        nonSelectedText: $(".multiple").attr("nonselectedtext")

    });




    $(".UpdateSelectedLanguageCode").change(function() {
        var language = $(this).val();
        var url = $("form").attr("action");
        url = url + "?language=" + language;
        parent.location = url;

    });


    if ($('.select2').length > 0) {
        $('.select2').select2();
    }

});


function FilterFormSubmit() {
    $("#IdsForApprove").val("");
    $("#IdsForSort").val("");
    $("#IdsForDelete").val("");
    $("#Paging_CurrentPage").val(1);
    $(".form-filter").submit();
}